package com.lanou.tk.tourism.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.android.volley.RequestQueue;
import com.lanou.tk.tourism.R;
import com.lanou.tk.tourism.adapter.CommunityRvAdapter;
import com.lanou.tk.tourism.entity.Hot_country;

import java.io.Serializable;
import java.util.List;

/**
 * Created by dllo on 15/10/28.
 */
public class CommunityCountry extends Fragment {
private TextView community_count,community_cnname,community_enname;
    private ImageView community_photo;

    private CommunityRvAdapter communityRvAdapter;
    private RecyclerView recyclerView;
    private RequestQueue queue;


    public static CommunityCountry newInstance(List<Hot_country> lanou){

        CommunityCountry Cc = new CommunityCountry();
        Bundle args = new Bundle();
        args.putSerializable("lanou",(Serializable) lanou);
//        args.putSerializable("id", );
        Cc.setArguments(args);
        return Cc;
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        return inflater.inflate(R.layout.community_rv,container,false);
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        initView(view);
    }

    private void initView(View view){
        community_count = (TextView) view.findViewById(R.id.community_count);
        community_cnname = (TextView) view.findViewById(R.id.community_cnname);
        community_enname = (TextView) view.findViewById(R.id.community_enname);
        community_photo = (ImageView) view.findViewById(R.id.community_photo);


        GridLayoutManager gridLayoutManager = new GridLayoutManager(getActivity(),2);
        gridLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        recyclerView = (RecyclerView) view.findViewById(R.id.community_rv);
        recyclerView.setLayoutManager(gridLayoutManager);
        communityRvAdapter = new CommunityRvAdapter(getActivity());
        recyclerView.setAdapter(communityRvAdapter);


    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        initData();
    }


    private void initData(){
        List<Hot_country> Hc = (List<Hot_country>) getArguments().getSerializable("lanou");
        communityRvAdapter.addDatas(Hc);

    }





}
